function singleNumber(nums) {
    let result = 0;
    for (let num of nums) {
        console.log(result);
        result ^= num;
    }
    return result;
}

const nums = [4, 1, 2, 1, 2];
console.log(singleNumber(nums)); // 输出 4